package freespiritsocial.io.user.ui.adapter.search

import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import freespiritsocial.io.user.R
import freespiritsocial.io.user.data.model.bean.SearchPojo
import freespiritsocial.io.user.databinding.ItemTagsBinding
import freespiritsocial.io.user.ext.init
import freespiritsocial.io.user.viewmodel.SearchViewModel

/**
 * 搜索tags
 */
class TagsAdapter(
    model: SearchViewModel,
    data: ArrayList<SearchPojo> = arrayListOf(),
    layoutResIdRes: Int = R.layout.item__tags
):
    BaseQuickAdapter<SearchPojo,BaseDataBindingHolder<ItemTagsBinding>>(layoutResIdRes,data),LoadMoreModule,
    ISearchAdapter by SearchDelegate(SearchViewModel.tags,model) {

    override fun convert(holder: BaseDataBindingHolder<ItemTagsBinding>,item: SearchPojo) = with(holder.dataBinding) {
        this?.recyclerViewImage?.init(
            getImageAdapter(item),
            LinearLayoutManager(context,RecyclerView.HORIZONTAL,false),
            hasEmpty = false
        )?.also {
            if (it.itemDecorationCount == 0)
                it.addItemDecoration(spaceItemDecoration)
        }
        this?.name = item.content
    }
}